home *** CD-ROM | disk | FTP | other *** search
- Path: gambier.ugrad.cs.ubc.ca!not-for-mail
- From: c2a192@ugrad.cs.ubc.ca (Kazimir Kylheku)
- Newsgroups: comp.lang.c
- Subject: Re: Handling complex numbers...
- Date: 5 Mar 1996 13:40:03 -0800
- Organization: Computer Science, University of B.C., Vancouver, B.C., Canada
- Message-ID: <4hicbjINN91t@gambier.ugrad.cs.ubc.ca>
- References: <4hi113$2i8k@mercury.cc.uottawa.ca>
- NNTP-Posting-Host: gambier.ugrad.cs.ubc.ca
-
- In article <4hi113$2i8k@mercury.cc.uottawa.ca>,
- Charles Tran <ctran@csi.uottawa.ca> wrote:
- >Dear fellow netters,
- >
- >Can someone kindly explain to me how to represent complex numbers in C?
-
- A structure containing the real and imaginary part can be sufficient.
-
- typedef struct {
- double real;
- double imag;
- } complex_t;
-
- >I am writing a numerical method program to calculate the area under
- >a curve using Simpson's Rule. The problem that I face right now is
- >the representation of "i" (where i^2 = -1) in my C program.
-
- complex_t i = { 0, 1 };
-
- :)
-
- >Here's a simple example of what I mean:
- >
- > _b
- > |
- > | exp(ix) dx
- >_|
- >a
- >
- >
- >How do I implement this function exp(ix)?
-
- Look up the definition in your text on complex analysis.
-
- exp(ix) = cos(x) + i sin(x), x real
-
-
- You might just want to implement exp(z), where z = x + iy, since z = it is just
- a special case. Again, just look up the definition!
-
- With the general purpose exp(z), you can loop a real number from a to b,
- multiply each step value by i, and then subject it to exp(z). As an
- optimization, you might want to have a special function or macro that
- multiplies by i, or take it outside the loop altogether.
-
- --
-
-